package jscinttools.datafit.scint;

import java.lang.StringBuilder;
import java.lang.String;

import jscinttools.datafit.scint.PulseFitFunc;

import hep.aida.IAnalysisFactory;
import hep.aida.ITreeFactory;
import hep.aida.ITree;
import hep.aida.IFunction;

/**
 *  Class to create a function Gaussian + Moyal defined as:
 *  Amp_g*exp(-((N-mu_g)/(2*sig_g))^2)+Amp_m*(exp(-((N-mu_m)/sig_m+exp(-(N-mu_m)/sig_m))))
 *
 *@author     Marc-Antoine Verdier
 *@created    8 avril 2011
 */
public class GaussMoyalFitFunc implements SpectrumFitFunc
{
	/**
	 *  Setup the fit function as Amp_g*exp(-((N-mu_g)/(2*sig_g))^2)+Amp_m*(exp(-((N-mu_m)/sig_m+exp(-(N-mu_m)/sig_m))))
	 *
	 *@param  param  The parameters defining the IFunction in this order:
	 *      Amp_g,mu_g,sig_g,Amp_m,mu_m,sig_m
	 *@return        The IFunction used for fitting
	 */
	public IFunction fitFunction(double[] param)
	{
		IFunction func = af.createFunctionFactory(af.createTreeFactory().create()).createFunctionFromScript("Moyal + Gauss", 1, "Amp_g*exp(-1.0*(x[0]-mu_g)*(x[0]-mu_g)/(2*sig_g*sig_g))+Amp_m*(exp(-1.0*((x[0]-mu_m)/sig_m+exp(-1.0*(x[0]-mu_m)/sig_m))))", "Amp_g,mu_g,sig_g,Amp_m,mu_m,sig_m", "Moyal + Gauss");
		func.setParameters(param);
		return func;
	}
}

